{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "d6564a42",
   "metadata": {},
   "outputs": [],
   "source": [
    "import numpy as np"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "93f676ea",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[0 1 2 3 4 5 6 7 8 9]\n",
      "int32\n"
     ]
    }
   ],
   "source": [
    "arr = np.arange(10)\n",
    "print(arr)\n",
    "print(arr.dtype)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "e4a8dbbd",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[1 2 3 4 5 6 7 8]\n",
      "int8\n"
     ]
    }
   ],
   "source": [
    "arr_int8 = np.array([1,2,3,4,5,6,7,8],dtype=np.int8)\n",
    "print(arr_int8)\n",
    "print(arr_int8.dtype)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "94045000",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[<__main__.Person object at 0x0000020C6EA8B190>\n",
      " <__main__.Person object at 0x0000020C6EA8BD90>]\n",
      "object\n"
     ]
    }
   ],
   "source": [
    "class Person:\n",
    "    def __init__(self,name,age):\n",
    "        self.name=name\n",
    "        self.age=age\n",
    "arr_p = np.array([Person(\"张三\",18),Person(\"李四\",19)])\n",
    "print(arr_p)\n",
    "print(arr_p.dtype)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "4328857e",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[1 2 3 4 5 6 7 8]\n",
      "int8\n",
      "[1 2 3 4 5 6 7 8]\n",
      "int64\n"
     ]
    }
   ],
   "source": [
    "# 修改类型\n",
    "arr_int8 = np.array([1,2,3,4,5,6,7,8],dtype=np.int8)\n",
    "print(arr_int8)\n",
    "print(arr_int8.dtype)\n",
    "arr_int64 = arr_int8.astype(np.int64)\n",
    "print(arr_int64)\n",
    "print(arr_int64.dtype)\n"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.8"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
